package com.example.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {
	
	public static final String TABLE_INPROGRESS = "table_in_progress";
	public static final String TABLE_FINISHED = "table_finsished";
	public static final String ID = "id";

	
	public static final String LOCAL_PATH = "local_path";
	public static final String REMOTE_PATH = "remote_path";

	public static final String START_POS= "start_pos";
	public static final String END_POS = "end_pos";
	public static final String COMPLETE_SIZE = "complete_size";
	
	public static final String STATE = "state";
	public static final String ERROR = "error";
	public static final String ERROR_CODE = "error_code";
	
	public DBHelper(Context context, String database_name, int database_version) 
	{
		super(context, database_name, null, database_version);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		createTable(db, TABLE_INPROGRESS);
		createTable(db, TABLE_FINISHED);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_INPROGRESS);
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_FINISHED);
		onCreate(db); 
	}
	
	public void createTable(SQLiteDatabase db, String table_name)
	{
		String sql = "CREATE TABLE IF NOT EXISTS " + table_name + "("
				+ ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
				
				
				+ LOCAL_PATH + " VARCHAR,"
				+ REMOTE_PATH + " VARCHAR,"
				
				+ START_POS + " LONG,"
				+ END_POS + " LONG,"
				+ COMPLETE_SIZE + " LONG,"

				+ STATE + " VARCHAR,"
				+ ERROR + " VARCHAR,"
				+ ERROR_CODE + " INTEGER "
				
				
			
				
				+")";
				
	
		db.execSQL(sql);
	}
}
